package com.atguigu.blog.service.impl;

import com.atguigu.blog.mapper.UserMapper;
import com.atguigu.blog.pojo.User;
import com.atguigu.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author 孤妤
 * @Date 2023/11/24 17:00
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    @Transactional(readOnly = true)
    public Map<String, Object> showByUsername(User user) {
        Map<String,Object> map = null;
        User loginUser = userMapper.selectByUsername(user.getUsername());
        if (loginUser!=null){
            if (loginUser.getPassword().equals(user.getPassword())){
                map = new HashMap<>();
                map.put("uid",loginUser.getUid());
                map.put("username",loginUser.getUsername());
            }
        }
        return map;
    }

    @Override
    @Transactional(readOnly = true)
    public User showByUid(Integer uid) {
        return userMapper.selectByUid(uid);
    }

    @Override
    public Integer change(User user) {
        return userMapper.update(user);
    }
}